#!/bin/sh

set_gpio() {
	[ "$2" -eq 1 ] && gpio set $1 || gpio clear $1
	sleep 1
}

# Generic RNDIS
if [ "$1" = "rndis-generic" ]; then
	modprobe rndis_host
	sleep 5
	exit 0
fi

# Huawei E3372H and eth1
if [ "$1" = "rndis-e3372h" ]; then
	usb_modeswitch -v 0x12d1 -p 0x1f01 -c /usr/share/usb_modeswitch/12d1:1f01
	modprobe rndis_host
	sleep 5
	exit 0
fi

# GK7205V200 Kafei with A7680C and usb0
if [ "$1" = "a7680c-gk7205v200-kafei" ]; then
	set_gpio 57 0
	modprobe usbserial vendor=0x1e0e product=0x9011
	modprobe rndis_host
	sleep 15
	exit 0
fi

# GK7205V200 Vixand with Quectel EC200N-CN and usb0
if [ "$1" = "ec200n-gk7205v200-vixand" ]; then
	set_gpio 0 0
	modprobe usbserial vendor=0x2c7c product=0x6002
	modprobe rndis_host
	sleep 10
	exit 0
fi

# T31 CamHi with Quectel EC200S-CN, EC200T-EU and usb0
if [ "$1" = "ec200s-t31-camhi" ]; then
	set_gpio 61 0
	modprobe usbserial vendor=0x2c7c product=0x6026
	modprobe rndis_host
	sleep 10
	exit 0
fi

# T31 CamHi with Quectel EC800G-CN and usb0
if [ "$1" = "ec800g-t31-camhi" ]; then
	set_gpio 61 0
	modprobe usbserial vendor=0x2c7c product=0x904
	modprobe rndis_host
	sleep 10
	exit 0
fi

# T31 CamHi with Fibocom L610-CN and usb0
if [ "$1" = "l610-t31-camhi" ]; then
	set_gpio 61 0
	modprobe usbserial vendor=0x1782 product=0x4d11
	modprobe rndis_host
	sleep 10
	echo "AT+GTRNDIS=1,2" >/dev/ttyUSB0
	exit 0
fi

# T31 CamHi with Fibocom L716-CN and usb0
if [ "$1" = "l716-t31-camhi" ]; then
	set_gpio 61 0
	modprobe usbserial vendor=0x2cb7 product=0x0001
	modprobe rndis_host
	sleep 10
	exit 0
fi

# SIMCOM7600G/SIMCOM7600G-H
if [ "$1" = "sim7600g" ]; then
	modprobe rndis_host
	modprobe option
	echo "1e0e 9011" > /sys/bus/usb-serial/drivers/option1/new_id
	sleep 5
	exit 0
fi

# EG25/EC25-xxx (RNDIS, AT+QCFG="usbnet",3)
if [ "$1" = "rndis-ec25" ]; then
	modprobe rndis_host
	modprobe option
	sleep 5
	exit 0
fi

# EG25/EC25-xxx (ECM, AT+QCFG="usbnet",1)
if [ "$1" = "ec25" ]; then
	modprobe option
	sleep 5
	exit 0
fi
exit 1
